﻿using System;
using System.Linq;

namespace HamcoWcs.Models.Monitors
{
    /// <summary>
    /// 电箱参数
    /// </summary>
    public sealed class CabinetPara : ParaBase
    {
        public double Temperature { get; set; }
        public double Humidity { get; set; }
        public double LVol_ab { get; set; }
        public double LVol_bc { get; set; }
        public double LVol_ca { get; set; }
        public double LVol_avg { get; set; }
        public double PVol_ab { get; set; }
        public double PVol_bc { get; set; }
        public double PVol_ca { get; set; }
        public double PVol_avg { get; set; }
        public double Current_a { get; set; }
        public double Current_b { get; set; }
        public double Current_c { get; set; }
        public double Current_avg { get; set; }
        public double ActiveElectricity { get; set; }
        public double ReactiveElectricity { get; set; }

        protected override int _len => 36;

        public CabinetPara(int index, string name) : base(index, name)
        {
        }

        public override void Update(byte[] content)
        {
            var t = GetTargetContent(content);
            Temperature = Reserve(BitConverter.ToUInt16(t, 0)) * 0.1;
            Humidity = Reserve(BitConverter.ToUInt16(t, 2)) * 0.1;
            LVol_ab = Reserve(BitConverter.ToUInt16(t, 4)) * 0.1;
            LVol_bc = Reserve(BitConverter.ToUInt16(t, 6)) * 0.1;
            LVol_ca = Reserve(BitConverter.ToUInt16(t, 8)) * 0.1;
            LVol_avg = Reserve(BitConverter.ToUInt16(t, 10)) * 0.1;
            PVol_ab = Reserve(BitConverter.ToUInt16(t, 12)) * 0.1;
            PVol_bc = Reserve(BitConverter.ToUInt16(t, 14)) * 0.1;
            PVol_ca = Reserve(BitConverter.ToUInt16(t, 16)) * 0.1;
            PVol_avg = Reserve(BitConverter.ToUInt16(t, 18)) * 0.1;
            Current_a = Reserve(BitConverter.ToUInt16(t, 20)) * 0.1;
            Current_b = Reserve(BitConverter.ToUInt16(t, 22)) * 0.1;
            Current_c = Reserve(BitConverter.ToUInt16(t, 24)) * 0.1;
            Current_avg = Reserve(BitConverter.ToUInt16(t, 26)) * 0.1;
            ActiveElectricity = BitConverter.ToUInt32(t.Skip(28).Take(4).Reverse().ToArray()) * 0.1;
            ReactiveElectricity = BitConverter.ToUInt32(t.Skip(32).Take(4).Reverse().ToArray()) * 0.1;
        }
    }
}
